<?php if( ! defined('BASEPATH')) exit('No direct script access allowed');
class Order extends Controller
{
	function Order()
	{
		parent::Controller();
		check_is_login();
		$this->load->model("admin/Order_model");
		$this->load->library('form_validation');
		$this->load->database();
	}
	function index()
	{
		$per_page = 20;
		$query = $this->Order_model->get_records($per_page);
		$this->db->select('status,count(status) AS snum');
		$this->db->group_by('status');
		$data = array(
				'query'		=> $query['query'],
				'paginate'	=> $query['paginate'],
				'order_nav' => $this->db->get('order')
		);
		$this->load->view(TPL_FOLDER."order_list",$data);
	}

	function del_record()
	{
		$this->form_validation->set_rules("rd_id","删除的记录","required");
		if($this->form_validation->run()==FALSE)
		{
			$tx_msg=validation_errors();
			echo_msg($tx_msg);
		}
		if($this->Order_model->del_record())
		{
			
			$tx_msg="<li>记录删除成功.</li>";
			echo_msg($tx_msg,'','yes');
		}
		else
		{
			$tx_msg="<li>记录删除失败.</li>";
			echo_msg($tx_msg);
		}
	}
	
	function ajax_toggle()
	{
		$this->form_validation->set_rules("rd_id","0","trim|required");
		if($this->form_validation->run()==FALSE)
		{
			die("0");
		}
		if($this->Order_model->ajax_toggle())
		{
			
			echo "1";
		}
		else
		{
			echo "0";
		}
	}
	
	function send_email()
	{
		$this->form_validation->set_rules("email","客户email","valid_email");
		$this->form_validation->set_rules("subject","邮件主题","required");
		$this->form_validation->set_rules("content","邮件内容","required");
		if($this->form_validation->run()==FALSE)
		{
			$tx_msg=validation_errors();
			echo_msg($tx_msg);
		}
		if(send_email($this->input->post('email'),$this->input->post('subject'),$this->input->post('content')))
		{
			$tx_msg="<li>邮件发送成功.</li>";
			echo_msg($tx_msg,'','yes');
		}
	}
}
?>